package veterinaria.servlet.publicidad;

import java.io.IOException;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.negocio.GestionPublicidad;

/**
 * Servlet implementation class PublicidadInsertarServlet
 */
@WebServlet("/PublicidadInsertarServlet")
public class PublicidadInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PublicidadInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String a = request.getParameter("titulo");		
		String b = request.getParameter("contenido");
		String c = request.getParameter("fechaInicio");
		String d = request.getParameter("fechaFin");
		Double e = Double.parseDouble(request.getParameter("tarifa"));
		int f = Integer.parseInt(request.getParameter("visitas"));
		String g = request.getParameter("ubicacion");
		
		
		GestionPublicidad negocio = new GestionPublicidad();
		try {
			negocio.insertar(a, b, c, d, e, f, g);
			//response.sendRedirect(request.getContextPath()	+ "/PublicidadBuscarServlet?publicidad");
			RequestDispatcher rd = request.getRequestDispatcher("exito.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion ex) {
			RequestDispatcher rd = request.getRequestDispatcher("errorNuevo.jsp");
			rd.forward(request, response);
		}
	}

}
